package com.poiapp;


import com.poiapp.excel.template.utils.PoiUtil;
import com.poiapp.model.ExcelTest;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;

public class First {


    public static void main(String[] args) throws Exception {

//        InputStream is = FileUtils.openInputStream(new File("D:\\test.xlsx"));
//        List list = PoiUtil.readExcel(is, "test.xlsx");
//
//        System.out.println();
//        IOUtils.closeQuietly(is);

        writeExcel();
    }

    private static void writeExcel() throws IOException {
        OutputStream os = FileUtils.openOutputStream(new File("D:\\list.xls"));
        List<ExcelTest> list = initData();
        Map<String, String> titleMap = new HashMap<String, String>();
        titleMap.put("姓名", "name");
        titleMap.put("年龄", "age");
        titleMap.put("性别", "gender");
        titleMap.put("出生日期", "birthDay");

        PoiUtil.writeExcel(list, os, titleMap);

        IOUtils.closeQuietly(os);
    }

    private static List<ExcelTest> initData() {
        List<ExcelTest> list = new ArrayList<ExcelTest>();
        for (int i = 0; i < 10; i++) {
            ExcelTest test = new ExcelTest("tt" + i, i, "男", new Date());
            if (i % 2 == 0) {
                test.setGender("女");
            } else {
                test.setGender("男");
            }
            list.add(test);
        }
        return list;
    }
}
